<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Login</title>
    <meta charset="utf-8">
    <script src="${pageContext.request.contextPath}/static/js/polyfill.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery/jquerymin.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery/jquery-1.11.0.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/axios-min.js"></script>
</head>
<body>
<script>
    var username;
    var password;
    var historyUrl;
    $(document).ready(function () {
       username = GetQueryString("userName");
       password = GetQueryString("password");
       historyUrl = GetQueryString("Historyurl")
       getBokeLogin(username,password);
    });
    function getBokeLogin(username,password) { //请求boke登录接口  直接跳转,抛弃现有接口
        axios({
            url:"/boke/applogin_mlogin.do?userName="+username+"&password="+password,
            method:"get",
        }).then(response=>{
            if(response.data.result==="login_ok"){
                if(historyUrl==="/bokehall/hall/allHall"){  //如果登录请求成功,并且过滤器请求为会诊大厅,则直接重新跳转
                    window.location.href=historyUrl+"?from=app";
                    return false;
                }
                sendBack("me") //登录成功的其他请求,先跳转回app"我的"页面
            }else{
                if(historyUrl==="/bokehall/hall/allHall"){ //失败同理
                    window.location.href=historyUrl+"?from=app";
                    return false;
                }
                sendBack("me");
            }
        }).catch(err=>{
            sendBack("me");
        })
    }
    function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return unescape(r[2]); return null;
    }
    function sendBack(state) {   //app跳转
        var data={"state":state };
        autoLogin.postMessage(JSON.stringify(data));
    }
</script>
</body>
</html>
